<% layout('layout') -%>
<div class="page-header">
  <div class="page-title">
    <h2>留言板互动</h2>
    <span>提交问题、反馈或招投标沟通信息</span>
  </div>
</div>

<div class="section-card">
  <form method="get" action="/messages" class="form-inline form-slim">
    <label>按招标 ID 筛选<input name="tender_id" value="<%= tenderId || '' %>"></label>
    <button type="submit" class="btn-outline">应用筛选</button>
  </form>

  <form method="post" action="/messages" class="form form-slim">
    <label>留言内容<textarea name="content" placeholder="写下想要交流的内容" required></textarea></label>
    <label>关联招标 ID（可选）<input name="tender_id" value="<%= tenderId || '' %>" placeholder="如需关联具体项目可填写"></label>
    <div class="form-actions">
      <button type="submit">发布留言</button>
    </div>
  </form>
</div>

<div class="table-wrapper">
  <table class="table">
    <thead>
      <tr>
        <th>ID</th>
        <th>作者</th>
        <th>关联招标</th>
        <th>内容</th>
        <th>时间</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody>
      <% messages.forEach(m => { %>
        <tr>
          <td><%= m.id %></td>
          <td><strong><%= m.username %></strong></td>
          <td><%= m.tender_id || '—' %></td>
          <td><%= m.content %></td>
          <td><%= m.created_at %></td>
          <td>
            <% if (currentUser && currentUser.role === 'ADMIN') { %>
              <form method="post" action="/admin/messages/<%= m.id %>/delete">
                <button type="submit" class="btn-danger">删除</button>
              </form>
            <% } %>
          </td>
        </tr>
      <% }) %>
    </tbody>
  </table>
</div>


